﻿#include<stdio.h>
#include<stdlib.h>
int* addToArrayForm(int* num, int numSize, int k, int* returnSize) {
    int nextnum = 0;
    int numSize_k = 0;
    int j = k;
    do
    {
        numSize_k++;
    } while (j /= 10);
    int len = numSize > numSize_k ? numSize : numSize_k;
    int* resultnum = (int*)malloc(sizeof(int) * (len + 1));
    int ret = 0;
    int Ai = numSize - 1;
    int i = 0;
    int resultSize = 0;
    while (len--)
    {
        int a = 0;
        if (Ai >= 0)
            a = num[Ai];
        ret = nextnum + a + k % 10;
        if (ret > 9)
        {
            nextnum = 1;
            ret -= 10;
        }
        else
            nextnum = 0;
        resultnum[i] = ret;
        resultSize++;
        Ai--;
        k /= 10;
        i++;
    }
    if (nextnum == 1)
    {
        resultnum[i] = nextnum;
        resultSize++;
    }
    int left = 0, right = resultSize - 1;
    while (left <= right)
    {
        int tmp = resultnum[left];
        resultnum[left] = resultnum[right];
        resultnum[right] = tmp;
        left++;
        right--;
    }
    *returnSize = resultSize;
    return resultnum;


}
int main()
{
    int num[] = {2,1,5};
    int returnSize[100];
    int* rs = addToArrayForm(num, 3,806, returnSize);
    
}